# -*- encoding:utf8 -*-

import re

print re.match("www","www.baidu.com").span()
print re.match("www","awww.baidu.com")
print re.search("www","awww.baidu.com").span()


line = "Process finished with exit code 0"
matchStr = re.search(r'(.*) with (.*?) .*',line,re.M|re.I)
if matchStr:
    print "matchStr group()",matchStr.group()
    print "matchStr group(1)",matchStr.group(1)
    print "matchStr group(2)",matchStr.group(2)
else:
    print "no match"

phone = "464-4616-16-4646-164-616-46-164-6164 奥萨蒂十大发生"

num = re.sub(r' .*$',"",phone)
print num
num = re.sub(r'\D',"",num)
print num

def double(mached):
    value = int(mached.group('value'))
    return str(value * 2)

s = 'sfd46sdf64sdf16'
print re.sub('(?P<value>\d+)',double,s)

pattern = re.compile(r'\d+')
m = pattern.match("sadgksd6456sdg13a1sdsadgf56")
print m
m = pattern.match("sadgksd6456sdg13a1sdsadgf56",6,30)
print m
m = pattern.match("sadgksd6456sdg13a1sdsadgf56",7,30)
print m.group()
print m.start()
print m.end()
print m.span()

print re.split(r"\d+","sdfsadf56sdf1261sadf561sad6f6")

# 解析身份证号码
idno = "430321199501173313"
str = re.search(r'(?P<province>\d{3})(?P<city>\d{3})(?P<birth_year>\d{4})(?P<birth_month>\d{2})(?P<birth_day>\d{2})(?P<number>\d{4})',idno)

print str.groupdict()
